/*
 * Created on Sep 12, 2006
 * 
 */

package com.probiz.estore.service;

import java.util.HashMap;
import java.util.Map;

import com.probiz.estore.framework.test.BaseGenericTransactionalTestCase;
import com.probiz.estore.system.service.MailQueueManager;
import com.probiz.estore.system.util.MailEngine;

/**
 * @author Legend
 * 
 */
public class MailEngineTestCase extends
		BaseGenericTransactionalTestCase<Object> {

	protected MailEngine		mailEngine	= null;

	private MailQueueManager	mailQueueManager;

	public void setMailEngine(MailEngine mailEngine) {
		this.mailEngine = mailEngine;
	}

	public void setMailQueueManager(MailQueueManager mailQueueManager) {
		this.mailQueueManager = mailQueueManager;
	}

	public void _testCleanExpiredEmails() throws Exception {
		logger.debug("cleaning...");
		long startTime = System.currentTimeMillis();
		// mailQueueManager.setDaysToKeep(1);
		mailQueueManager.cleanExpiredEmails();
		setComplete();
		logger.warn("Clean time:" + (System.currentTimeMillis() - startTime));
	}

	public void testComposeMail1() throws Exception {
		logger.debug("Compose and queue mail...");
		long startTime = System.currentTimeMillis();
		Map model = new HashMap();
		model.put("url", "If you can read this url, it means it really works now.");
		mailEngine.sendSimpleTemplateMail(
				"activateUser.vm", model, null, null,
				"pengzhirong@probiz.cn");
		setComplete();
		logger.warn("Compose and queue time:"
				+ (System.currentTimeMillis() - startTime));
	}

	public void _testComposeMail2() throws Exception {
		logger.debug("Compose and queue mail...");
		long startTime = System.currentTimeMillis();
		Map model = new HashMap();
		model.put("url",
				"If you can read this url, it means it really works now.");
		mailEngine.sendSimpleTemplateMail(
				"!/velocity/passwordRecover.vm", model, null, null,
				"legend@probiz.cn");
		setComplete();
		logger.warn("Compose and queue time:"
				+ (System.currentTimeMillis() - startTime));
	}

	public void _testComposeMail3() throws Exception {
		logger.debug("Compose and queue mail...");
		long startTime = System.currentTimeMillis();
		Map model = new HashMap();
		model.put("url",
				"If you can read this url, it means it really works now.");
		mailEngine.sendSimpleTemplateMail(
				"!/velocity/passwordRecover.vm", model, null, null,
				"legend@probiz.cn");
		setComplete();
		logger.warn("Compose and queue time:"
				+ (System.currentTimeMillis() - startTime));
	}

	public void _testResetEmails() throws Exception {
		logger.debug("reset...");
		long startTime = System.currentTimeMillis();
		mailQueueManager.resetIncorrectEmails();
		setComplete();
		logger.warn("reset time:" + (System.currentTimeMillis() - startTime));
	}

	public void _testSendQueuedEmails() throws Exception {
		/**
		 * int numOfEmailsPerTime = 3; logger.debug("sending..." +
		 * numOfEmailsPerTime + " emails."); long startTime =
		 * System.currentTimeMillis();
		 * mailEngine.setNumOfEmailsPerTime(numOfEmailsPerTime);
		 * mailEngine.sendQueuedEmails(); setComplete(); logger.warn("sent.
		 * time:" + (System.currentTimeMillis() - startTime));
		 */
	}
}
